package com.dongdongshop.service.imp;

import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.page.PageBeen;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TbSellerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class TbSellerServiceImp implements TbSellerService {
    @Autowired
    private TbSellerMapper tbSellerMapper;
    @Override
    public PageBeen<TbSeller> selectSeller(String name, String nickName, String status, Integer pageNum, Integer pageSize) {
       PageHelper.startPage(pageNum,pageSize);
        List<TbSeller> list = tbSellerMapper.selectSeller(name,nickName,status);
        PageInfo<TbSeller> pageInfo = new PageInfo<>(list);
        PageBeen<TbSeller> pageBeen = new PageBeen<>(pageNum,pageSize,pageInfo.getTotal(),pageInfo.getList(),pageInfo.getPages());
        return pageBeen;
    }

    @Override
    public TbSeller toUpdate(String sellerId) {
        return tbSellerMapper.selectByPrimaryKey(sellerId);
    }

    @Override
    public int update(String sellerId, String status) {
        return tbSellerMapper.updateStatus(sellerId,status);
    }

    @Override
    public TbSeller showUser(String sellerId) {
        TbSeller tbSeller = tbSellerMapper.selectByPrimaryKey(sellerId);
        return tbSeller;
    }


    @Override
    public int selectUname(String sellerId) {
        TbSeller tbSeller = tbSellerMapper.selectUname(sellerId);
        if (tbSeller == null){
            return 1;
        }
        return 0;
    }

    @Override
    public int addInf(TbSeller tbSeller) {
        return tbSellerMapper.insertSelective(tbSeller);
    }
}
